const Koa = require('koa');
let app = new Koa();
const static = require('koa-static');
const fs = require('fs');
const { getConfig } = require('./config');
let { target, port, routePrefix } = getConfig();
const { resolve } = require('path');
const { historyApiFallback } = require('koa2-connect-history-api-fallback');
const handleDir = require('./filters/handle-dir');

// 支持 vue-router  hash 模式的中间件
// app.use(handleDir)

// 支持 vue-router  H5 history 模式的中间件
// whiteList 内设置的字符串会被转换为正则，与 ctx.url 进行匹配，匹配的会 略过此中间件功能
app.use(historyApiFallback({ 
    whiteList: ['/api'],
    index: `${routePrefix}/index.html`  //正常为 mobile/1.0.0/index.html，开启多皮肤就是 theme_pink/1.0.0/index.html 这样了
 }));

// 静态资源路径为上层 public
app.use(static(resolve(__dirname, `../${target}`)));

app.listen(port, ()=>{
    console.log(`Start listening on port ${port}...`)
});